package server;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author lbq
 * @version 1.0
 * @date 2021/1/21 21:38
 */
public class Request {

    private String url;
    private String method;
    private InputStream in;

    public Request(InputStream inputStream) throws IOException {
        this.in = inputStream;

        int count = 0;
        while (count == 0) {
            count = inputStream.available();
        }

        byte[] bytes = new byte[count];
        inputStream.read(bytes);

        String inputStr = new String(bytes);
        // 获取第一行请求头信息
        String firstLineStr = inputStr.split("\\n")[0];  // GET / HTTP/1.1

        String[] strings = firstLineStr.split(" ");

        this.method = strings[0];
        this.url = strings[1];

        System.out.println("=====>>method:" + method);
        System.out.println("=====>>url:" + url);
    }

    public String getUrl() {
        return url;
    }

    public String getMethod() {
        return method;
    }
}
